package com.anjubao.parking.municipal.parkinglot.service;

import com.anjubao.parking.municipal.common.exception.ServiceException;
import com.anjubao.parking.municipal.parkinglot.mapper.ParkingLotBillRuleRelateMapper;
import com.anjubao.parking.municipal.parkinglot.model.ParkingLotBillRuleRelate;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import javax.annotation.Resource;
import java.util.List;

/**
 * 停车场-收费规则关联表Service
 *
 * @author zhuchunfeng
 */
@Service
@Slf4j
public class ParkingLotBillRuleRelateService{

    @Resource
    private ParkingLotBillRuleRelateMapper parkingLotBillRuleRelateMapper;

    public ParkingLotBillRuleRelate getByParkingLotId(Long parkingLotId) {
        List<ParkingLotBillRuleRelate> parkingLotBillRuleRelates = parkingLotBillRuleRelateMapper.selectList(new QueryWrapper<>(new ParkingLotBillRuleRelate().setParkingLotId(parkingLotId)));
        if (CollectionUtils.isEmpty(parkingLotBillRuleRelates)) {
            throw new ServiceException("无停车位与计费规则关联关系");
        }
        return parkingLotBillRuleRelates.get(0);
    }
}
